package org.sage.sdk.dada.infrastructure.common.response;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;

/**
 * @author 周广明
 * @version v1 2019/12/11 下午2:06
 */
@Data
public class BaseResponse<T> {

    /**
     * 响应状态，成功为"success"，失败为"fail"
     */
    String status;

    /**
     * 响应返回码，参考接口返回码
     */
    Integer code;

    /**
     * 响应描述
     */
    String msg;

    /**
     * 响应结果，JSON对象，详见具体的接口描述
     */
    JSONObject result = new JSONObject();

    /**
     * 错误编码，与code一致
     */
    Integer errorCode;

    T objData;

    public BaseResponse data(T data) {
        this.objData = data;
        return this;
    }

    public T getData() {
        return objData;
    }

    private static final int STATUS_CODE = -2;

    private final static String STATUS_MSG = "请求超时异常";

    public static BaseResponse except() {
        BaseResponse apiResponse = new BaseResponse();
        apiResponse.setCode(STATUS_CODE);
        apiResponse.setMsg(STATUS_MSG);
        return apiResponse;
    }

}
